﻿using System;
using System.Web;

namespace WebDiagnostics.Diagnosers.ServerInfo
{
    [DiagnoserDescriptor("Server Information", Priority = 1)]
    public class ServerInfoDiagnoser : IDiagnoser
    {
        public Diagnosis Diagnose(HttpContextBase context)
        {
            var process = System.Diagnostics.Process.GetCurrentProcess();

            var serverInfo = new ServerInfoDiagnosis()
                {
                    IISVersion = context.Request["SERVER_SOFTWARE"],
                    MaxAllocatedMemory = process.MaxWorkingSet.ToInt64(),
                    Name = Environment.MachineName,
                    OSVersion = Environment.OSVersion.ToString(),
                    PhysicallyAllocatedMemory = process.WorkingSet64,
                    ThreadCount = process.Threads.Count,
                    UsedMemory = process.PrivateMemorySize64,
                };

            return serverInfo;
        }
    }
}
